package com.example.service.webhook.business.security.api;

import com.example.service.webhook.api.MoxieClient;
import com.example.service.webhook.business.security.dto.SecurityDetails;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;

/**2017/4/8
 * create by vivicat
 */
@Component
public class SecurityClient extends MoxieClient{
	
	 private SecurityApi api;

	 @Autowired
	public SecurityClient(@Value("${moxie.api.baseUrl}") String apiBaseUrl,
                          @Value("${moxie.api.token}") String apiToken) {
		super(apiBaseUrl, apiToken);
		api = retrofit.create(SecurityApi.class);
	}

	private static final Logger LOGGER = LoggerFactory.getLogger(SecurityClient.class);
	
	
	
	public SecurityDetails getSecurity(String taskId) throws IOException {
        Call<SecurityDetails> call = api.getSecurity(taskId);
        Response<SecurityDetails> response = call.execute();
        if (response.code() == 200) {
            return response.body();
        } else {
            LOGGER.info("getSecurity, status:{}, message:{}", response.code(), response.message());
        }
        return null;
    }
	
	
	
}
  
